/*
 * FileSizeFormatter.java
 *
 * Created on December 6, 2006, 1:00 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package eu.somatik.somaftp.logic;

/**
 *
 * @author francisdb
 */
public class FileSizeFormatter {
    
    public static final long UNIT = 1024;
    
    /** Creates a new instance of FileSizeFormatter */
    private FileSizeFormatter() {
        super();
    }
    
    public static final String format(long bytes){
        String result = null;
        
        if(bytes < 0){
            result = "";
        }else if(bytes < UNIT){
            result = String.valueOf(bytes);
        }else if (bytes < UNIT * UNIT){
            result = Math.round(bytes/UNIT) + "KB";
        }else if (bytes < UNIT * UNIT * UNIT){
            result = Math.round(bytes/(UNIT*UNIT)) + "MB";
        }else{
            result = Math.round(bytes/(UNIT*UNIT*UNIT)) + "GB";
        }
        
        return result;
    }
    
}
